package com.spring_mysql_redis.controller;

import com.spring_mysql_redis.annotation.CurrentUser;
import com.spring_mysql_redis.entity.UserLikes;
import com.spring_mysql_redis.entity.Users;
import com.spring_mysql_redis.model.ResultFormat;
import com.spring_mysql_redis.service.UserLikesService;
import com.spring_mysql_redis.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "redis点赞管理")
@RestController
@RequestMapping("/likes")
public class UserLikesController {

    private Logger logger = LoggerFactory.getLogger(UserLikesController.class);

    @Autowired
    private UserLikesService userlikesService;

    @ApiOperation("查询点赞接口")
    @GetMapping("/select")
    public ResultFormat selectLike(@RequestParam("dynamicId") Integer dynamicId, @CurrentUser Users user) {

        logger.info("userLikes=={}", dynamicId);
        Integer state = userlikesService.selectLike(dynamicId, user.getId());
        if (state != null){
            return ResultUtil.success(state);
        }
        return ResultUtil.error(100, "查询失败");
    }

    @ApiOperation("点赞接口")
    @GetMapping("/addLike")
    public Object PgSorts(@RequestParam("dynamicId") Integer dynamicId, @CurrentUser Users user) {
        System.out.println(dynamicId+"--------------------------------------------------------------------------------");
        logger.info("dynamicId=={}", dynamicId);
        Object flag = userlikesService.likeState(dynamicId,user.getId());
        return flag;

    }
}
